<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------
// 应用公共文件


/**
 * @param int $status
 * @param int $code
 * @param string $data
 * @param string $msg
 * @param int $type
 * @return false|string
 * 通用返回json格式
 */
function jsonReturn($status=0, $code=0, $data='', $msg='',$type = 1)
{

    $json_arr = array('status'=>$status,'code'=>$code);
    if(!empty($msg)){
        $json_arr['msg'] = $msg;
    }
    if(!empty($data)){
        $json_arr['data'] = $data;
    }
    header('Content-Type:application/json; charset=utf-8');
    if ($type == 1) {
        exit(json_encode($json_arr));
    } else if ($type == 2) {
        return json_encode($json_arr);
    }
}

/**
 * @param $array
 * @return array|string
 * 数组去空格
 */
function array_trim($array){
    if(!is_array($array)){
        return trim($array);
    }
    return array_map('array_trim', $array);
}